<?php include("header.php") ?>

<section class="page container">
    <div class="row">

    </div>
    <div class="row">
        <div class="span12">
            <div class="box">
                <div class="box-header">
                    <i class="icon-bookmark"></i>
                    <h5>Quick Forms</h5>
                </div>
                <div class="box-content">
                    <div class="btn-group-box">
                        <a class="btn" href="<?php nav_url("petrostock") ?>" style="width:71px;"><h6>Solid
                                Petro-Stock</h6></a>
                        <a class="btn" style="width:71px;"><h6>Technical</h6></a>
                        <a class="btn" style="width:71px;"><h6>Anjur site-Asha</h6></a>
                        <a class="btn" style="width:71px;"><h6>Sarika Accounting</h6></a>
                        <a class="btn" style="width:71px;"><h6>Marketing</h6></a>
                        <a class="btn" style="width:71px;"><h6>CS</h6></a>
                        <a class="btn" style="width:71px;"><h6>Finance</h6></a>
                        <a class="btn" style="width:71px;"><h6>Legal</h6></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="span4">
            <div class="box pattern pattern-sandstone">
                <div class="box-header">
                    <i class="icon-list"></i>
                    <h5>Recent Activities</h5>
                </div>
                <div class="box-content box-list collapse in">
                    <input type="hidden" id="activityId" name="activityId">
                    <ul id="recentActivity" style="max-height: 600px;overflow-y: hidden;">
                    </ul>
                </div>

            </div>
        </div>
    </div>
</section>
<?php include("footer.php") ?>
<script>
    $(document).ready(function () {
        $.get("<?php nav_url('dashbord/activities') ?>", function (data) {
            prependAtTop(data, false);
        });
    });

    setInterval(recentUserActivity, 3000);

    function prependAtTop(data, isPrepentToTop) {
        var json = JSON.parse(data);
        if (json != null) {
            for (var i = 0; i < json.length; i++) {
                if($('ul#recentActivity li').length > 15){
                    $('#recentActivity li:last-child').remove();
                }
                var vDate = moment(json[i].date.date, "YYYY-MM-DD h:mm:ss");
                vDate = new Date(vDate);
                var strDate = moment(json[i].date.date).format("DD-MMM-YYYY");
                var htmlActivity = "<li><div><a href='#' class='news-item-title'>" + json[i].user.firstName + " " + json[i].user.lastName + "</a><span class='pull-right'><time class='timeago' datetime='" + vDate.toISOString() + "'>" + strDate + "</time></span>";
                htmlActivity += "<p class='news-item-preview'>" + json[i].description + "</p></div></li>";
                if(isPrepentToTop){
                    $(htmlActivity).hide().prependTo("#recentActivity").slideDown("slow");
                    $("#activityId").val(json[i].id);
                }else{
                    $(htmlActivity).hide().appendTo("#recentActivity").slideDown("slow");
                    if(i == 0){
                        $("#activityId").val(json[i].id);
                    }
                }
            }
            jQuery("time.timeago").timeago();
        }
    }

    function recentUserActivity() {
        var url = "<?php nav_url("dashbord/recentActivity/")?>";
        $.get(url + $("#activityId").val(), function (data) {
            prependAtTop(data, true);
        });
    }
</script>

</body>
</html>